import {FullTimeEmployee, PartTimeEmployee} from './Employees';

interface Department{
  visitFullTimeEmployee(employee:FullTimeEmployee):void;
  visitPartTimeEmployee(employee:PartTimeEmployee):void;
}

/**
 * 人力资源部
 * 人力资源部计算每个员工的工作时长
 */
class HRDepartment implements Department{
  visitFullTimeEmployee(employee:FullTimeEmployee):void{
    let workTime = createRandomWorkTime(10, 6, 5);
    employee.setWorkTime(workTime);
    if(workTime > 40){
      // 加班
      console.log(`正式员工#${employee.name}# 本周工作[${workTime}]小时，加班[${workTime - 40}]小时`);
    }else if(workTime < 40){
      console.log(`正式员工#${employee.name}# 本周工作[${workTime}]小时，缺勤[${40 - workTime}]小时`);
    }else{
      console.log(`正式员工#${employee.name}# 本周工作[${workTime}]小时`);
    }
  }
  visitPartTimeEmployee(employee:PartTimeEmployee):void{
    let workTime = createRandomWorkTime(10, 6, 5);
    employee.setWorkTime(workTime);
    console.log(`临时员工#${employee.name}# 本周工作[${workTime}]小时`);
  }
}

/**
 * 财务部
 * 财务部根据人力资源部计算工作时间统计每个员工的工资
 * */
class FADepartment implements Department{
  visitFullTimeEmployee(employee:FullTimeEmployee):void{
    // 全职员工按周计薪
    let workTime:number = employee.getWorkTime();
    let weekWage:number = employee.getWeeklyWage();
    if(workTime > 40){
      weekWage = weekWage + (workTime - 40) * 10;
    }else{
      weekWage = weekWage - (40 - workTime) * 5;
      if(weekWage < 0){
        weekWage = 0;
      }
    }
    console.log(`正式员工#${employee.name}# 本周薪资[${weekWage}]元`);
  }
  visitPartTimeEmployee(employee:PartTimeEmployee):void{
    let workTime:number = employee.getWorkTime();
    let hourWage:number = employee.getHourWage();
    console.log(`临时员工#${employee.name}# 本周薪资[${workTime*hourWage}]元`);
  }
}

// 根据某些条件（打卡时间）计算此员工工作时长，这里随机生成（每天0-12小时，工作5天）
function createRandomWorkTime(maxHours:number, minHours:number, days:number):number{
  return (Math.floor(Math.random() * (maxHours - minHours + 1)) + minHours)*days;
}

export {
  Department,
  FADepartment,
  HRDepartment
};